package com.fuchun.animloadingprogress;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private AnimLoadingProgress animLoadingProgress;
    private int progress;

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            progress += new Random().nextInt(6);
            if(progress>100){
                progress = 100;
            }else{
                handler.sendEmptyMessageDelayed(0,500);
            }
            animLoadingProgress.setProgress(progress);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        animLoadingProgress = findViewById(R.id.pro_anim);
    }

    public void onStartClickListener(View view){
        progress = 0;
        animLoadingProgress.startLoading();
        handler.sendEmptyMessageDelayed(0,1000);
    }
}
